<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--suppress ALL-->
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户管理</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
  <style>
    .id{
      display: none;
    }
    a{
      cursor: pointer;
    }
  </style>
<script type="text/javascript" src="../../js/jquery.js"></script>
<script type="text/javascript">
var IsPublic;
var id;
function tipOpen(content) {
	$(".tipright p").text(content);
	$("#tip").fadeIn(200);
}
function allottipOpen() {
	$("#allottip").fadeIn(200);
}
function allottipclose() {
	$("#allottip").fadeOut(200);
}
function tipClose(info) {
  if (info!=''&&info!=null){
    var $info = $(info).val();
    if ($info=='确定'){
      $.ajax({
        url:'/office/updateContact',
        type:'post',
        dataType:'json',
        data:{'id':id,'IsPublic':IsPublic},
        success:function (result) {
          if (result){
            alert('修改成功');
            id='';
            window.location = '/office/queryContactsTypeList';
          }else {
            alert('修改失败');
          }
        }
      })
    }
  }
  $("#tip").fadeOut(200);
}
function rename(){
    var name = $('#rename').val();
    if (name!=null && name!=''){
      $.ajax({
        url:'/office/updateContact',
        type:'post',
        dataType:'json',
        data:{'id':id,'name':name},
        success:function (result) {
          if (result){
            alert('修改成功');
            window.location = '/office/queryContactsTypeList';
          }else {
            alert('修改失败');
          }
        }
      })
  }
  $("#tip").fadeOut(200);
}
function subFrom() {
  $("#subfrom").submit();
}
function removeTheContactType(node) {
  var ids =new Array();
  var id = $(node).parents('tr').children('.id').html();
  ids.push(id);
  $.ajax({
    url:'/office/removeContactType',
    type:'post',
    dataType:'json',
    data:{ids,ids},
    success:function (result) {
      if (result){
        alert('删除成功')
        $(node).parents('tr').remove();
      }else {
        alert('删除失败')
      }
    }
  })
}
$(function () {
  var totalPage = parseInt($('.totalPage').html());
  var pageNum = parseInt($('.pageNum').html());
  function nextPage(totalPage,pageNum) {
    if (pageNum>=totalPage){
      alert("这是最后一页了")
    }else{
      pageNum++;
      $('.pageNum').html(pageNum);
      $('#subfrom').submit();
    }
  }
  function rePage(pageNum) {
    if (pageNum<=1){
      alert("这是已经是第一页了")
    }else{
      pageNum--;
      $('.pageNum').html(pageNum);
      $('#subfrom').submit();
    }
  }
  $('.pagepre').click(function () {
    rePage(pageNum);
  })
  $('.pagenxt').click(function () {
    nextPage(totalPage,pageNum);
  })
  /*修改公开状态*/
  $('.setStatus').click(function () {
    var status = $(this).next().html();
    var tipText = status=='公开'?'确认设置为不公开吗？':'确认设置为公开吗？'
    id = $(this).parents('tr').children('.id').html();
    IsPublic = status=='公开'?0:1;
    tipOpen(tipText);
  })
  /*重命名*/
  $('.rename').click(function () {
    id = $(this).parents('tr').children('.id').html();
    $('#renameTip').fadeIn(200);
  })
})
</script>
</head>

<body>
  <div class="place"> <span>位置：</span>
    <ul class="placeul">
      <li>个人办公</li>
      <li>名片夹</li>
      <li>名片夹列表</li>
    </ul>
  </div>

<div class="rightinfo">
  <form id="subfrom" th:action="@{/office/queryContactsTypeList}" method="post">
      <ul class="tools">
        <li> 名片夹名称:
          <input name="name" type="text" size="12" th:value="${ContactsTypeCondition!=null?ContactsTypeCondition.name:''}"/>
        </li>
        <li> 创建人:
          <input name="uname" type="text" size="12" th:value="${ContactsTypeCondition!=null?ContactsTypeCondition.uname:''}"/>
        </li>
        <li> 状态：
          <select name="IsPublic">
            <option value="">请选择</option>
            <option th:each="status:${statusList}" th:value="${status}" th:text="${status}==1?'公开':'不公开'" th:selected="${ContactsTypeCondition.IsPublic eq status}">公开</option>
          </select>
        </li>
        <li class="subBut sunFrom" onclick="subFrom();"><img src="../../images/t06.png" />查询</li>
        <li class="subBut" onclick="window.location.href='/office/contactsAdd'"><img src="../../images/t01.png" />添加</li>
        <li class="subBut" onclick="window.location.href='/office/queryContactsTypeListByUser'">查看我的文件夹</li>
      </ul>
      <table class="tablelist">
        <thead>
        <tr>
          <th>序号</th>
          <th>名片夹名称</th>
          <th>创建人</th>
          <th>操作</th>
          <th>状态</th>
        </tr>
        </thead>
        <tbody>
        <!--<tr>
          <td>1</td>
          <td>王金平</td>
          <td>男</td>
          <td>17370899727</td>
          <td>
          	<a href="contactsView.html" class="tablelink">查看详情</a>
          </td>
        </tr>-->
        <th:block th:each="contact:${contactsTypePageModel.data}">
          <tr>
            <td th:text="${contactStat.index+1}">1</td>
            <td th:text="${contact.id}" class="id">id</td>
            <td th:text="${contact.name}">名片夹名字</td>
            <td th:text="${contact.user.uname}">aa</td>
            <td>
              <a href="storageView.html" th:href=" ${contact.IsPublic}==1?'/office/queryContactsList?typeId='+${contact.id}:'javascript:alert('+'这个名片夹内容未公开'+')'" class="tablelink">查看名片夹</a>
              <th:block th:if="${contact.createStuffId}==${session.user.userId}">
                <a class="tablelink rename">重命名</a>
                <a th:text="'设置为'+${contact.IsPublic==1?'不公开':'公开'}" href="javascript:void(0)" class="tablelink setStatus">公开</a>
                <a onclick="removeTheContactType(this)" class="tablelink">删除</a>
              </th:block>
            </td>
            <td th:text="${contact.IsPublic==1?'公开':'不公开'}">公开</td>
          </tr>
        </th:block>
        </tbody>
      </table>
      <div class="pagin">
        <div class="message">共<i class="blue" th:text="${contactsTypePageModel.totalRows}">1256</i>条记录(<i class="blue totalPage" th:text="${contactsTypePageModel.totalPage}"></i>页)，当前显示第&nbsp;<i class="blue pageNum" name="pageNum" th:text="${contactsTypePageModel.pageNum}">2&nbsp;</i>页</div>
        <ul class="paginList">
          <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
          <li class="paginItem"><a th:text="${contactsTypePageModel.pageNum}" href="javascript:;">1</a></li>
          <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
        </ul>
      </div>
    <!-- 提示框 -->
    <div id="tip" class="tip">
      <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
      <div class="tipinfo"> <span><img src="../../images/ticon.png" /></span>
        <div class="tipright">
          <p></p>
          <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
      </div>
      <div class="tipbtn">
        <input name="" type="button"  class="sure" value="确定" onclick="tipClose(this)" />
        &nbsp;
        <input name="" type="button"  class="cancel" value="取消" onclick="tipClose(this)" />
      </div>
    </div>
</form>
    <!-- 重命名提示框 -->
      <div id="renameTip" class="tip">
        <div class="tiptop"><span>提示信息</span><a onclick="script:$('#renameTip').hide();"></a></div>
        <div class="tipinfo">
          <div class="tipright">
            <p>请输入修改的名字：</p>
            <input type="text" id="rename">
          </div>
        </div>
        <div class="tipbtn">
          <input name="" type="button"  class="sure" value="确定" onclick="rename()" />
          &nbsp;
          <input name="" type="button"  class="cancel" value="取消" onclick="script:$('#renameTip').hide();" />
        </div>
      </div>
  </div>


<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');

</script>
</body>
</html>
